package com.mrduan.otgfilemanager.ui_sdcard.video.adapter;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.VideoView;

import com.bumptech.glide.Glide;
import com.mrduan.otgfilemanager.R;
import com.mrduan.otgfilemanager.ui.video.VideoMsgBean;

import java.util.List;

import cn.jzvd.JZVideoPlayer;
import cn.jzvd.JZVideoPlayerStandard;

/**
 * Created by snoopy on 2018/4/28.
 */

public class ListVideoAdapter extends BaseAdapter {

    private Context mContext;
    private List<VideoMsgBean> mFiles;

    private int startPlay;

    public void setStartPlay(int startPlay) {
        this.startPlay = startPlay;

        notifyDataSetChanged();

    }

    public ListVideoAdapter(Context mContext, List<VideoMsgBean> mFiles) {

        JZVideoPlayer.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;  //横向
        JZVideoPlayer.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;  //纵向

        this.mContext = mContext;
        this.mFiles = mFiles;
    }

    @Override
    public int getCount() {
        return mFiles.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            LayoutInflater mInflater = LayoutInflater.from(mContext);
            convertView = mInflater.inflate(R.layout.list_video_adapter, null);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        VideoMsgBean bean = mFiles.get(position);

        viewHolder.jzVideoPlayer = convertView.findViewById(R.id.videoplayer);
        viewHolder.jzVideoPlayer.setUp(
                bean.getPath(), JZVideoPlayer.SCREEN_WINDOW_LIST,
                bean.getTitle());
        Glide.with(convertView.getContext())
                .load(bean.getPicPath())
                .into(viewHolder.jzVideoPlayer.thumbImageView);
        viewHolder.jzVideoPlayer.positionInList = position;
        return convertView;
    }

    class ViewHolder {
        JZVideoPlayerStandard jzVideoPlayer;
    }

}
